package com.sky.controller.user;

import com.sky.dto.UserLoginDTO;
import com.sky.pojo.User;
import com.sky.result.Result;
import com.sky.service.user.UserService;
import com.sky.vo.UserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
//import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

/**
 * @Description UserController
 * @Author lyh
 * @Date 2024-09-30
 */
@RestController
@RequestMapping("/user/user")
@Api(tags = "用户端相关接口")
public class UserController {
    @Autowired
    private UserService userService;
    /**
     * 微信小程序登录
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("微信小程序登录")
    public Result<UserLoginVO> login(@RequestBody UserLoginDTO dto){
     UserLoginVO userLoginVO=userService.login(dto);
     return Result.success(userLoginVO);
    }
    @GetMapping("/getById")
    @Cacheable(value="user",key="#id")
    public User getById(Long id){
        return userService.getById(id);
    }
    @DeleteMapping("/delete")
    @CacheEvict(value="user",key="#id")
    public void deleteById(Long id){
        userService.deleteById(id);
    }
}
